﻿using DH.Core.Helper;
using DH.Service.Domain;
using DH.Service.Domain.User;
using DH.Service.ViewModels.Dto;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DH.Web.MVC
{
    public class UserSessionEx:UserSession
    {
        //public UserSession UserSession { get; set; }
        
        protected PrivilegeService _privilegeService;
        protected UserService _userService;
        public UserSessionEx(IServiceCollection serviceCollection)
        {
            _privilegeService=serviceCollection.BuildServiceProvider().GetService<PrivilegeService>();
        }

        
        public List<RoleMenuDto> RoleMenus {
            get {
                return _privilegeService.GetByQuery(c => c.SubjectType == PrivilegeTypeEnum.Role.ToString() && RoleId.Contains(c.SubjectId) && c.ObjectType == PrivilegeTypeEnum.Menu.ToString()).Select(c=>new RoleMenuDto {
                    SubjectId=c.SubjectId,
                    SubjectType=c.SubjectType,
                    ObjectId=c.ObjectId,
                    ObjectType=c.ObjectType
                }).ToList();
            }
        }

        public List<RoleFunctionDto> RoleFuncs {
            get {
                return _privilegeService.GetByQuery(c => c.SubjectType == PrivilegeTypeEnum.Role.ToString() && RoleId.Contains(c.SubjectId) && c.ObjectType == PrivilegeTypeEnum.Function.ToString())
                    .Select(c=>new RoleFunctionDto {
                    SubjectType=c.SubjectType,
                    SubjectId=c.SubjectId,
                    ObjectType=c.ObjectType,
                    ObjectId=c.ObjectId
                }).ToList();
            }
        }

        //public string UserImg
        //{
        //    get
        //    {
        //        var res= _userService.GetByQuery(c => c.DH_EnableMark == true && c.DH_DeleteMark == false && c.DH_Account == UserId);
        //        if (res.Any())
        //        {
        //            return res.First().DH_HeadIcon;
        //        }
        //        else
        //        {
        //            return "/content/img/samples/mrhua.jpg";
        //        }
        //    }
        //}

    }
}
